#import "Pref.h"

@implementation Preferences

- awakeFromNib
{
  [ self revert:self ];

  return self;
}

- save:sender
{
  static NXDefaultsVector newDefaults = {
    "Printed",		0,
    "Fixed",		0,
    "Precision",	0,
    0,			0,
  };

  newDefaults[ 0 ].value = [ printerButton state ] ? "1" : "0";
  newDefaults[ 1 ].value = [ fixButton state ] ? "1" : "0";
  newDefaults[ 2 ].value = (char *)[ precisionPopUpButton title ];

  NXWriteDefaults( "Calculette", newDefaults );

  return self;
}

- revert:sender
{
  [ printerButton setState:strcmp( NXGetDefaultValue( "Calculette", "Printed" ), "0" ) ];
  [ fixButton setState:strcmp( NXGetDefaultValue( "Calculette", "Fixed" ), "0" ) ];

  [[ precisionPopUpList itemList ] selectCellWithTag:atoi( NXGetDefaultValue( "Calculette", "Precision" )) ];
  [ precisionPopUpButton setTitle:[[[ precisionPopUpList itemList ] selectedCell ] title ]];

  return self;
}

@end
